# create a new nuancier server
# NOTE: should be used with --limit most of the time
# NOTE: make sure there is room/space for this server on the vmhost
# NOTE: most of these vars_path come from group_vars/nuancier* or from hostvars

- include: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=nuancier:nuancier-stg"

- name: make the box be real
  hosts: nuancier;nuancier-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - base
  - rkhunter
  - { role: denyhosts, when: ansible_distribution_major_version|int != 7 }
  - nagios_client
  - hosts
  - fas_client
  - collectd/base
  - sudo
  - { role: openvpn/client,
      when: env != "staging" }
  - apache

  tasks:
  - include: "{{ tasks }}/yumrepos.yml"
  - include: "{{ tasks }}/2fa_client.yml"
  - include: "{{ tasks }}/motd.yml"
  - include: "{{ tasks }}/mod_wsgi.yml"

  handlers:
  - include: "{{ handlers }}/restart_services.yml"

- name: set up fedmsg
  hosts: nuancier;nuancier-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - fedmsg/base

  handlers:
  - include: "{{ handlers }}/restart_services.yml"

- name: set up gluster on stg
  hosts: nuancier-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: gluster/server
    name: gluster
    username: "{{ nuancier_gluster_username }}"
    password: "{{ nuancier_gluster_password }}"
    owner: root
    group: root
    datadir: /srv/glusterfs/nuancier-stg

  - role: gluster/client
    name: gluster
    servers:
    - nuancier01.stg.phx2.fedoraproject.org
    - nuancier02.stg.phx2.fedoraproject.org
    username: "{{ nuancier_gluster_username }}"
    password: "{{ nuancier_gluster_password }}"
    owner: apache
    group: root
    mountdir: /var/cache/nuancier

- name: set up gluster on prod
  hosts: nuancier
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: gluster/server
    name: gluster
    username: "{{ nuancier_gluster_username }}"
    password: "{{ nuancier_gluster_password }}"
    owner: root
    group: root
    datadir: /srv/glusterfs/nuancier

  - role: gluster/client
    name: gluster
    servers:
    - nuancier01.phx2.fedoraproject.org
    - nuancier02.phx2.fedoraproject.org
    username: "{{ nuancier_gluster_username }}"
    password: "{{ nuancier_gluster_password }}"
    owner: apache
    group: root
    mountdir: /var/cache/nuancier

- name: deploy nuancier itself
  hosts: nuancier;nuancier-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - "{{ vars_path }}/{{ ansible_distribution }}.yml"

  roles:
  - nuancier

  handlers:
  - include: "{{ handlers }}/restart_services.yml"
